#include <sstream>
#include "transportchannel.h"

namespace cricket
{
	std::string TransportChannel::ToString()
	{
		const char READABLE_ABBREV[2] = { '_', 'R' };
		const char WRITABLE_ABBREV[2] = { '_', 'W' };
		std::stringstream ss;
		ss << "Channel[" << content_name_
			<< "|" << component_
			<< "|" << READABLE_ABBREV[readable_] << WRITABLE_ABBREV[writable_] << "]";
		return ss.str();
	}

	void TransportChannel::set_readable(bool readable)
	{
		if (readable_ != readable) {
			readable_ = readable;
			SignalReadableState(this);
		}
	}

	void TransportChannel::set_writable(bool writable)
	{
		if (writable_ != writable) {
			writable_ = writable;
			if (writable_) {
				SignalReadyToSend(this);
			}
			SignalWritableState(this);
		}
	}
}